home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1996 #6
/
Amiga Plus CD - 1996 - No. 06.iso
/
pd
/
programmierung
/
proasm
/
routines
/
numbers.mac
< prev
next >
Wrap
Text File
|
1994-04-01
|
3KB
|
200 lines
;---; numbers.r ;------------------------------------------------------------
*
* **** NUMBER IN & OUTPUT ROUTINES ****
*
* Author Stefan Walter
* Version 1.01
* Last Revision 25.06.93
* Identifier nio_defined
* Prefix nio_ (number in out)
* ¯ ¯ ¯
* Macros GetHexNumber_, GetDecNumber_
*
;------------------------------------------------------------------------------
;------------------
ifnd nio_defined
nio_defined =1
;------------------
nio_oldbase equ __base
base nio_base
nio_base:
;------------------
;------------------------------------------------------------------------------
*
* GetHexNumber_ Try to get a hexadecimal number. "$" and C-style "0x"
* introducers supported
*
* INPUT: a0 String to interprete.
*
* RESULT: d0 Result.
* d1 0 if error, -1 if okay.
* ccr On d1.
*
;------------------------------------------------------------------------------
;------------------
; Macro
;
GetHexNumber_ macro
ifd nio_GetHexNumber
bsr nio_GetHexNumber
else
pea .nio_end1(pc)
;------------------
; Remove spaces first
;
nio_GetHexNumber = *
move.l d2,-(sp)
.sloop: cmp.b #" ",(a0)+
beq.s .sloop
tst.b -(a0)
beq.s .error
cmp.b #$a,(a0)
beq.s .error
cmp.b #"0",(a0)+
bne.s .dol
move.b (a0)+,d0
and.b #$df,d0
cmp.b #"X",d0
beq.s .nowcomesnumber
subq.l #1,a0
.dol: cmp.b #"$",-(a0)
bne.s .nowcomesnumber
addq.l #1,a0
.nowcomesnumber:
moveq #0,d0
.numberloop:
move.b (a0)+,d2
move.b d2,d1
beq.s .done
cmp.b #" ",d2
beq.s .done
cmp.b #$a,d2
beq.s .done
sub.b #"0",d2
blt.s .error
cmp.b #10,d2
blt.s .okay
move.b d1,d2
and.b #$df,d2
sub.b #"A",d2
blt.s .error
cmp.b #5,d2
bhi.s .error
add.b #10,d2
.okay: lsl.l #4,d0
or.b d2,d0
bra.s .numberloop
.error: move.l (sp)+,d2
moveq #0,d1
rts
.done: move.l (sp)+,d2
moveq #-1,d1
rts
;------------------
; End of macro.
;
.nio_end1:
endif
endm
;------------------
;------------------------------------------------------------------------------
*
* GetDecNumber_ Try to get a decimal number.
*
* INPUT: a0 String to interprete.
*
* RESULT: d0 Result.
* d1 0 if error, -1 if okay.
* ccr On d1.
*
;------------------------------------------------------------------------------
;------------------
; Macro
;
GetDecNumber_ macro
ifd nio_GetDecNumber
bsr nio_GetDecNumber
else
pea .nio_end2(pc)
;------------------
; Remove spaces first
;
nio_GetDecNumber = *
movem.l d2/d3,-(sp)
.sloopd: cmp.b #" ",(a0)+
beq.s .sloopd
tst.b -(a0)
beq.s .errord
cmp.b #$a,(a0)
beq.s .errord
.nowcomesnumberd:
moveq #0,d0
.numberloopd:
moveq #0,d2
move.b (a0)+,d2
move.b d2,d1
beq.s .doned
cmp.b #" ",d2
beq.s .doned
cmp.b #$a,d2
beq.s .doned
move.l d0,d3
lsl.l #3,d0 ;
add.l d3,d0 ;
add.l d3,d0 ; d0*10
sub.b #"0",d2
blt.s .errord
cmp.b #10,d2
bhs.s .errord
add.l d2,d0
bra.s .numberloopd
.errord:moveq #0,d1
.exitd: movem.l (sp)+,d2/d3
rts
.doned: moveq #-1,d1
bra.s .exitd
;------------------
; End of macro.
;
.nio_end2:
endif
endm
;------------------
;--------------------------------------------------------------------
;------------------
base nio_oldbase
;------------------
endif
end